<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\video\admin;

use app\admin\controller\Admin;
use app\common\builder\ZBuilder;

use think\facade\Hook;

/**
 * 视频举报
 * @package app\video\admin
 */
class Report extends Admin
{
    /**
     * 首页
     * @author jason wang <120907037@qq.com>
     * @return mixed
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function index(){
        cookie('__forward__', $_SERVER['REQUEST_URI']);
        
        // 获取筛选
        $map = $this->getMap();//dump($map);die;

        //tab
        $list_tab = [
            'tab1' => ['title' => '待审核', 'url' => url('index', ['group' => 'tab1'])],
            'tab2' => ['title' => '有效举报', 'url' => url('index', ['group' => 'tab2'])],
            'tab3' => ['title' => '无效举报', 'url' => url('index', ['group' => 'tab3'])],
        ];

        // 数据列表
        $data = input();
        $group = isset($data['group']) ? $data['group'] : 'tab1';
        switch ($group) {
            case 'tab1':
                $map[] = ['report_status', '=', 0];
                break;
            case 'tab2':
                $map[] = ['report_status', '=', 1];
                break;
            case 'tab3':
                $map[] = ['report_status', '=', 2];
                break;
        }

        // 数据列表
        $data_list = model('VideoPlayReport', 'model') -> where($map) -> order('create_time desc') -> paginate();
        //$data_list = controller('Vodlogic', 'logic') -> getVideoList();
        $rel_list =[];
		
		$play_report = play_report();//举报理由
		$play_report = array_column($play_report, 'report_type');
		$report = [];
		foreach ($play_report as $key =>$value){
			foreach($value as $v){  
				$k = $v['id'];
				$report[$k]=$v['name'];  
			}  
		}
        foreach ($data_list as $key => $value) {
            if(!isset($value->getVideoPlay)) continue;
            $rel_list[$key] = $value->toArray();
            $rel_list[$key]['username']                = $value->getUcMember->nick_name.'('.$value["uid"].')';
			$rel_list[$key]['play_name']               = $value->getVideoPlay->main_title.'('.$value["play_id"].')';
            $rel_list[$key]['report_name']             = isset($report[$value['reason']]) ? $report[$value['reason']] : '未知原因';
            $rel_list[$key]['report_status']           = $value->getData('report_status');
        }// dump($rel_list);die;
        // 详情
        $btn_details = [
            'title' => '视频详情',
            'icon'  => 'fa fa-fw fa-bookmark',
            //'class' => 'btn-default',
            'href'  => url('index/details', ['id' => '__play_id__'])
        ];
		
		// 举报详情
        $btn_report = [
            'title' => '举报详情',
            'icon'  => 'fa fa-fw fa-bookmark',
            //'class' => 'btn-default',
            'href'  => url('report', ['id' => '__id__'])
        ];
        // 使用ZBuilder快速创建数据表格
        return ZBuilder::make('table')
            ->setPageTitle('视频举报') // 设置页面标题
            ->setPrimaryKey('id') // 设置主键名为username
            ->setTableName('video_play_report') // 设置数据表名
            ->setTabNav($list_tab,  $group)
            //->setSearch(['id' => '艺人ID', 'artist_name' => '艺人名称', 'uid' => '会员UID']) // 设置搜索参数
            ->addColumns([ // 批量添加列
                //['__INDEX__', '序号'],
                ['id', 'id'],
                ['play_name', '视频名称'],
                ['username', '举报人'],
                ['report_name', '举报理由'],
                ['describe', '举报内容'],
                ['report_status', '状态', 'status', '', [0 => '待审核:default', 1 => '有效举报:success', 2 => '无效举报:danger']],
                ['right_button', '操作', 'btn']
            ])
            ->addFilter(['report_status']) // 添加筛选
            ->addRightButton('custom', $btn_details, true) // 添加授权按钮
            ->addRightButton('custom', $btn_report, true) // 添加授权按钮
            //->addTopButtons('delete') // 批量添加顶部按钮
            //->addRightButtons('delete') // 批量添加右侧按钮
            //->setPages($page) // 设置分页数据
            ->setRowList($rel_list) // 设置表格数据
            ->fetch(); // 渲染页面
    } 
	
	 /**
     * 举报详情
     * @author shiqiang
     * @return mixed
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
	public function report($id = []){
		$info = model('VideoPlayReport', 'model') -> find($id);
		$info['img_url'] = $info['img_url_1'] . ',' . $info['img_url_2'] . ',' . $info['img_url_3'] . ',' . $info['img_url_4'];
		
		$play_report = play_report();//举报理由
		$play_report = array_column($play_report, 'report_type');
		$report = [];
		foreach ($play_report as $key =>$value){
			foreach($value as $v){  
				$k = $v['id'];
				$report[$k]=$v['name'];  
			}  
		}
		
		$username 		= $info -> getUcMember->nick_name.'('.$info["uid"].')';
		$play_name 		= $info -> getVideoPlay->main_title.'('.$info["play_id"].')';
		$report_name	= isset($report[$info['reason']]) ? $report[$info['reason']] : '未知原因';
        //批量审核最多允许20个
		return ZBuilder::make('form')
            ->setPageTitle('申请详情') // 设置页面标题
            ->addFormItems([ // 批量添加表单项
                ['text', 'username', '举报人', '', $username, '', 'readonly="readonlys"'],
                ['text', 'play_name', '视频名称', '', $play_name, '', 'readonly="readonlys"'],
                ['text', 'report_name', '举报理由', '', $report_name, '', 'readonly="readonlys"'],
                ['textarea', 'describe', '举报详情', '', '', 'readonly="readonlys"'],
                ['text', 'report_status', '当前状态', '', [0 => '待审核:default', 1 => '有效举报:success', 2 => '无效举报:danger'], '', 'readonly="readonlys"'],
            ])
			->addGallery('img_url', '举报图片')
			->hideBtn(['submit', 'back'])
			->setFormData($info) // 设置表单数据
            ->fetch();
	}
    
}
